home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / enqueue.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  111 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: enqueue.c,v 1.5 1996/08/13 13:56:01 digulla Exp $
  4.     $Log: enqueue.c,v $
  5.     Revision 1.5  1996/08/13 13:56:01  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.4  1996/08/01 17:41:10  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. /* I want the macros */
  17. #define AROS_ALMOST_COMPATIBLE
  18. #include "exec_intern.h"
  19.  
  20. /*****************************************************************************
  21.  
  22.     NAME */
  23.     #include <exec/lists.h>
  24.     #include <clib/exec_protos.h>
  25.  
  26.     __AROS_LH2I(void, Enqueue,
  27.  
  28. /*  SYNOPSIS */
  29.     __AROS_LHA(struct List *, list, A0),
  30.     __AROS_LHA(struct Node *, node, A1),
  31.  
  32. /*  LOCATION */
  33.     struct SysBase *, SysBase, 45, Exec)
  34.  
  35. /*  FUNCTION
  36.     Sort a node into a list. The sort-key the field node->ln_Pri.
  37.  
  38.     INPUTS
  39.     list - Insert into this list. The list has to be in descending
  40.         order in respect to the field ln_Pri of all nodes.
  41.     node - This node is to be inserted. Note that this has to
  42.         be a complete node and not a MinNode !
  43.  
  44.     RESULT
  45.  
  46.     NOTES
  47.     The list has to be in descending order in respect to the field
  48.     ln_Pri of all nodes.
  49.  
  50.     EXAMPLE
  51.     struct List * list;
  52.     struct Node * node;
  53.  
  54.     // Sort the node at the correct place into the list
  55.     Enqueue (list, node);
  56.  
  57.     BUGS
  58.  
  59.     SEE ALSO
  60.  
  61.     INTERNALS
  62.  
  63.     HISTORY
  64.     26-08-95    digulla created after EXEC-Routine
  65.     26-10-95    digulla adjusted to new calling scheme
  66.  
  67. ******************************************************************************/
  68. {
  69.     __AROS_FUNC_INIT
  70.     struct Node * next;
  71.  
  72.     assert (list);
  73.     assert (node);
  74.  
  75.     /* Look through the list */
  76.     for (next=GetHead(list); next; next=GetSucc(next))
  77.     {
  78.     /*
  79.         if the NEXT node has lower prio than the new node, insert us
  80.         before the next node
  81.     */
  82.     if (node->ln_Pri >= next->ln_Pri)
  83.     {
  84.         /* Same as insert but insert before instead of insert behind */
  85.         node->ln_Succ = next;
  86.         node->ln_Pred = next->ln_Pred;
  87.  
  88.         next->ln_Pred->ln_Succ = node;
  89.         next->ln_Pred       = node;
  90.  
  91.         /*
  92.         Done. We cannot simly break the loop because of the AddTail()
  93.         below.
  94.         */
  95.         return;
  96.     }
  97.     }
  98.  
  99.     /*
  100.     If no nodes were in the list or our node has the lowest prio,
  101.     we add it as last node
  102.     */
  103.     node->ln_Succ           = (struct Node *)&list->lh_Tail;
  104.     node->ln_Pred           = list->lh_TailPred;
  105.  
  106.     list->lh_TailPred->ln_Succ = node;
  107.     list->lh_TailPred           = node;
  108.     __AROS_FUNC_EXIT
  109. } /* Enqueue */
  110.  
  111.